package com.xmmj.main.viewmodel

import android.view.View
import com.xmmj.common.router.RouteNavigator.routeMain
import com.xmmj.baselibrary.base.activity.mvvm.BaseViewModel
import androidx.databinding.ObservableField
import com.xmmj.main.model.MainModel
import com.xmmj.module_main.R

class LoginViewModel : BaseViewModel<MainModel>() {
    //账号
    var mAccount = ObservableField<String>()

    //密码
    var mPassword = ObservableField<String>()

    //点击登录事件
    var clickLogin = View.OnClickListener {
        launch {
            //显示loading
            showLoading(true)
            //登录
            mModel!!.login(mAccount.get()!!, mPassword.get()!!)
            //隐藏loading
            hideLoading()
            //提示登录成功
            toast(applicationContext.getString(R.string.login_success))
            //发送重载页面的事件
            postReLoadEvent()
            //跳转到首页
            routeMain()
        }
    }
}